#include "aquam8628.h"

Aquam8628::Aquam8628(QWidget *parent):Switch(parent)
{
    main_layout_ = new QVBoxLayout(this);

    back_widget_ = new QWidget(this);
    back_widget_->setObjectName("MainWidget");
    back_widget_->setStyleSheet("#MainWidget{background-color: rgb(0, 0, 0);border:2px solid rgb(197,197,197);border-radius:8px;}");

    main_layout_->addWidget(back_widget_);
    main_layout_->setContentsMargins(0,0,0,0);
    main_layout_->setSpacing(0);
    this->setLayout(main_layout_);

    switch_name_ = new QLabel(back_widget_);
    switch_name_->setStyleSheet("color: rgb(209, 183, 118);font:20pt 'Arial'");
}

void Aquam8628::InitSwtichName(QString name)
{
    switch_name_->resize(this->width()/3,this->height()/10);
    switch_name_->move(this->width()/3,10);
    switch_name_->setText(name);
}

void Aquam8628::InitSwitchPorts(QStringList &portnamelist)
{
    if(port_name_list_.length() > 24)
        return;
    for (int i=0;i<24 ;i++ ) {
        QLabel *_port_name = new QLabel(back_widget_);
        _port_name->setStyleSheet("color: rgb(255,255,255);font:12pt 'Arial';");
        _port_name->setGeometry(20+(i/4)*70,260-(i%4)*70,56,16);
        _port_name->setText(portnamelist.at(i));
        _port_name->setAlignment(Qt::AlignCenter);
        port_name_list_.append(_port_name);
        QLabel *_port = new QLabel(back_widget_);
//        if(portnamelist.at(i) == "spare" || portnamelist.at(i) == "Spare")
//            _port->setStyleSheet("background-color: rgb(147,147,147);border-radius:8px;");
//        else
        _port->setStyleSheet("background-color: rgb(255, 0, 0);border-radius:8px;");
        _port->setGeometry(40+(i/4)*70,280-(i%4)*70,16,16);
        port_list_.append(_port);
        QLabel *_port_number = new QLabel(back_widget_);
        _port_number->setStyleSheet("color: rgb(255,255,255);font:12pt 'Arial';");
        _port_number->setGeometry(40+(i/4)*70,300-(i%4)*70,16,16);
        _port_number->setText(QString("%1").arg(i+1));
        _port_number->setAlignment(Qt::AlignCenter);
    }
}

int Aquam8628::portCount()
{
    return port_list_.length();
}

void Aquam8628::updatePortStat(int port_index, int port_stat, int duplex_stat)
{
    if(port_index >= port_list_.length())
        return;
    if(port_stat == 0)
        port_list_[port_index]->setStyleSheet("background-color: red;border-radius:8px;");
    else if(port_stat == 1)
    {
        if(duplex_stat == 1)
            port_list_[port_index]->setStyleSheet("background-color:rgb(219,219,0);border-radius:8px;");
        else if(duplex_stat == 0)
            port_list_[port_index]->setStyleSheet("background-color: rgb(0, 255, 0);border-radius:8px;");
    }
}

void Aquam8628::updatePortsName(QStringList &portnamelist)
{
    for(int i=0;i<port_list_.length() && i< portnamelist.length();i++)
    {
        port_name_list_[i]->setText(portnamelist.at(i));
    }
}
